    package cn.tedu.micro.demo.client.exchange;

    import cn.tedu.micro.demo.client.RabbitChannelManager;
    import com.rabbitmq.client.BuiltinExchangeType;
    import com.rabbitmq.client.Channel;
    import lombok.extern.slf4j.Slf4j;
    import org.junit.jupiter.api.Test;

    import java.io.IOException;

    /**
     * 测试发布订阅交换机
     */
    @Slf4j
    public class FanoutExchange {
        //按照笔记的结构 声明queue1 2 3 fanout_ex交换机 声明绑定
        @Test
        public void fanoutBindQueues() throws IOException {
            //1.获取连接
            Channel channel = RabbitChannelManager.newChannel();
            //2.队列queue1 2 3 重复使用 重置清空
            channel.queueDelete("queue1");
            channel.queueDelete("queue2");
            channel.queueDelete("queue3");
            //3.声明3个队列
            channel.queueDeclare("queue1", false, false, false, null);
            channel.queueDeclare("queue2", false, false, false, null);
            channel.queueDeclare("queue3", false, false, false, null);
            //4.声明交换机,只需要2个参数 一个是交换机名字 ,一个是交换机类型
            channel.exchangeDeclare("fanout_ex", BuiltinExchangeType.FANOUT);
            //5.绑定队列 和 交换机 使用路由key值
            channel.queueBind("queue1","fanout_ex","北京");
            channel.queueBind("queue2","fanout_ex","上海");
            channel.queueBind("queue3","fanout_ex","天津");
        }
    }
